home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1997 / HAM Radio 1997.iso / vcls / libox / lbox.pas < prev    next >
Pascal/Delphi Source File  |  1996-04-08  |  2KB  |  77 lines

  1. (*
  2.   The ListBox component (Standard palette) in the
  3.   original Delphi release failed to publish an OnChange
  4.   event.  This is the event generated any time the user
  5.   moves the list box cursor bar and probably the most
  6.   important list box event.
  7.  
  8.   This component is derived from the ListBox class and
  9.   incorporates and publishes the OnChange event.
  10.  
  11.   To add this component to your VCL, do the following:
  12.  
  13.      1. Compile this file.
  14.      2. Make sure the resulting DCU is where Delphi
  15.         can find it.
  16.      3. Place the bitmap file (LBOX.DCR) with the
  17.         DCU file.
  18.      4. Use the Install Components item of the Options
  19.         menu to install.
  20.  
  21.    Jeeze, did Borland make it easy or what???!!
  22.  
  23. *)
  24.  
  25.  
  26. UNIT Lbox;
  27.  
  28. INTERFACE
  29.  
  30. USES
  31.   SysUtils, WinTypes, Messages, Classes, Controls, Graphics, Forms,
  32.   Menus, StdCtrls;
  33.  
  34. Type
  35.   TMyListBox = Class(TListBox)
  36.     private
  37.       FOnChange : TNotifyEvent;
  38.       FLastSel : integer;
  39.       procedure Click; override;
  40.     protected
  41.       procedure Change; Virtual;
  42.     published
  43.       property OnChange : TNotifyEvent read FOnChange write FOnChange;
  44.     public
  45.       constructor create(AOwner : TComponent); override;
  46.   End;
  47.  
  48. Procedure Register;
  49.  
  50. IMPLEMENTATION
  51.  
  52. procedure TMyListBox.Change;
  53. begin
  54.   FLastSel := ItemIndex;
  55.   if assigned(FOnChange) then FOnChange(self);
  56. end;
  57.  
  58. procedure TMyListBox.Click;
  59. begin
  60.   inherited Click;
  61.   if FLastSel <> ItemIndex then
  62.      Change;
  63. end;
  64.  
  65. constructor TMyListBox.Create;
  66. begin
  67.   Inherited Create(AOwner);
  68.   FLastSel := -1;
  69. end;
  70.  
  71. procedure Register;
  72. begin
  73.   RegisterComponents('Newlin',[TMyListBox]);
  74. end;
  75.  
  76. END.
  77.